/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package xmlparse;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;

/**
 *
 * @author kylin
 */
public class XMLParse {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String path=System.getProperty("user.dir")+"/plugsin.xml";
        File xmlfile=new File(path);
        boolean exist=xmlfile.exists();
        PluginWriter writer=new PluginWriter();
        
        if(!exist){
            xmlfile=writer.create(path);
        }
        System.out.println("exist:"+xmlfile.exists());
        writer.setXml(xmlfile);
        Element root=writer.getRoot();
        
//        for(int i=1;i<=10;i++){
//            BeanPlugin plug=new BeanPlugin();
//            plug.setId(i);
//            plug.setName("name"+i);
//            //plug.setLocation("location"+i);
//            plug.setClazz("class"+i);
//            plug.setCategory("category"+i);
//            plug.setVersion("version"+i);
//            plug.setDescription("description"+i);
//            plug.setAuthor("author"+i);
//            plug.setEmail("email"+i);
//            
//            if(i%2==0){
//                plug.setAutoload(true);
//            }else{
//                plug.setAutoload(false);
//            }
//            writer.addElement(root,plug);
//            writer.write();
//        }


        List list=writer.getPlugins(root);
        Iterator itor=list.iterator();
        while(itor.hasNext()){
            BeanPlugin p=(BeanPlugin)itor.next();
            System.out.println("id:["+p.getId()+"] autoload:["+p.isAutoload()+"] name:["+p.getName()+"] email:["+p.getEmail()+"]");
        }
    }
}
